<template>
    <span class="buttons drag-region">
        <div class="custom-title-bar">
          <p class="app-title">{{ appName }} <span class="version">v{{ appVersion }}</span></p>
        </div>
        <div class="window-controls">
            <button class="control-btn minimize-btn" @click="minimizeWindow" title="最小化">
                <svg class="btn-icon" viewBox="0 0 12 12" width="12" height="12" xmlns="http://www.w3.org/2000/svg">
                    <path d="M2 6h8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
                </svg>
            </button>
            <button class="control-btn maximize-btn" @click="toggleMaximize" title="最大化">
                <svg class="btn-icon" viewBox="0 0 12 12" width="12" height="12" xmlns="http://www.w3.org/2000/svg">
                    <path d="M2 2h8v8H2z" fill="none" stroke="currentColor" stroke-width="1.5"/>
                </svg>
            </button>
            <button class="control-btn close-btn" @click="closeWindow" title="关闭">
                <svg class="btn-icon" viewBox="0 0 12 12" width="12" height="12" xmlns="http://www.w3.org/2000/svg">
                    <path d="M3 3l6 6M9 3l-6 6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
                </svg>
            </button>
        </div>
    </span>
</template>

<script setup lang="ts">
import { getAppName, getAppVersion } from '../../electron/windowManager/getAppInfo';
import { ref, onMounted } from 'vue';

// 显示应用名称和版本号
const appName = ref('');
const appVersion = ref('');
onMounted(() => {
  appName.value = getAppName();
  appVersion.value = getAppVersion();
});

declare const electronAPI: any;

const minimizeWindow = () => electronAPI.minimizeWindow('minimize-window');
const toggleMaximize = () => electronAPI.toggleMaximize('toggle-maximize');
const closeWindow = () => electronAPI.closeWindow('close-window');
</script>

<style scoped>
.drag-region {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 32px;
  -webkit-app-region: drag;
  background: rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  justify-content: space-between;
  align-items: center;
  z-index: 9999;
}

.custom-title-bar {
  display: flex;
  align-items: center;
  padding-left: 16px;
  -webkit-app-region: drag;
  flex-grow: 1;
}

.app-title {
  color: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  font-weight: 500;
  margin: 0;
  letter-spacing: 0.3px;
}

.version {
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  font-weight: 400;
  margin-left: 4px;
}

.window-controls {
  display: flex;
  align-items: center;
  gap: 1px;
  margin-right: 8px;
  -webkit-app-region: no-drag;
}

.control-btn {
  width: 32px;
  height: 24px;
  border: none;
  outline: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-app-region: no-drag;
  position: relative;
  z-index: 10000;
}

.control-btn:focus {
  outline: none;
  box-shadow: none;
}



.control-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 1);
  transform: translateY(-0.5px);
}

.control-btn:active {
  transform: translateY(0);
  background: rgba(255, 255, 255, 0.15);
}

.minimize-btn:hover {
  background: rgba(255, 193, 7, 0.15);
  color: #ffc107;
}

.maximize-btn:hover {
  background: rgba(40, 167, 69, 0.15);
  color: #28a745;
}

.close-btn:hover {
  background: rgba(220, 53, 69, 0.15);
  color: #dc3545;
}

/* 添加微妙的阴影效果 */
.control-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 4px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
  opacity: 0;
  transition: opacity 0.2s ease;
}

.control-btn:hover::before {
  opacity: 1;
}

.btn-icon {
    display: block;
    width: 12px;
    height: 12px;
    color: inherit;
    fill: currentColor;
    stroke: currentColor;
    pointer-events: none;
    flex-shrink: 0;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .drag-region {
    height: 28px;
  }
  
  .control-btn {
    width: 28px;
    height: 20px;
  }
  
  .control-btn svg {
    width: 10px;
    height: 10px;
  }
  
  .app-title {
    font-size: 12px;
  }
  
  .version {
    font-size: 10px;
  }
}
</style>
